# Paragraphe 3.1 Simulated distributions
library(actuar)
x1<-seq(0,10,0.001)
x2<-seq(0,5,0.001)
x3<-seq(0.001,5,0.001)
x4<-seq(0.001,7,0.001)

#Normal distribution
d1<-dnorm(x1,mean=5,sd=1)
fdr1<-pnorm(x1,mean=5,sd=1)
q1<-qnorm(0.95,mean=5,sd=1)

#Weibull distribution
d2<-dweibull(x2,shape=1.5,scale=1)
fdr2<-pweibull(x2,shape=1.5,scale=1)
q2<-qweibull(0.95,shape=1.5,scale=1)

#Lognormal distribution
d3<-dlnorm(x3,meanlog=0,sdlog=0.5)
fdr3<-plnorm(x3,meanlog=0,sdlog=0.5)
q3<-qlnorm(0.95,meanlog=0,sdlog=0.5)

#Mixture Pareto/lognormal
#30%-70%
d4<-0.7*dlnorm(x4,meanlog=0,sdlog=0.5)+0.3*dpareto(x4,shape=1.5,scale=1)
fdr4<-0.7*plnorm(x4,meanlog=0,sdlog=0.5)+0.3*ppareto(x4,shape=1.5,scale=1)
quantiles4<-cbind(x4,fdr4)
q4<-quantiles4[fdr4>0.95][1]
#70%-30%
d5<-0.3*dlnorm(x4,meanlog=0,sdlog=0.5)+0.7*dpareto(x4,shape=1.5,scale=1)
fdr5<-0.3*plnorm(x4,meanlog=0,sdlog=0.5)+0.7*ppareto(x4,shape=1.5,scale=1)
quantiles5<-cbind(x4,fdr5)
q5<-quantiles5[fdr5>0.95][1]


#Graphiques pour le compte rendu
plot(x1,d1,type="l",main="Normal distribution",sub="mean=5 sd=1",col="dark magenta",xlab="",ylab="Normal density",lwd=2,cex.main=0.8,cex.lab=0.8,cex.axis=0.8,cex.sub=0.8)
plot(x2,d2,type="l",main="Weibull distribution",sub="shape=1.5 scale=1",col="dark magenta",xlab="",ylab="Weibull density",lwd=2,cex.main=0.8,cex.lab=0.8,cex.axis=0.8,cex.sub=0.8)
plot(x3,d3,type="l",main="Lognormal distribution",sub="mean=0 sd=0.5",col="dark magenta",xlab="",ylab="Lognormal density",lwd=2,cex.main=0.8,cex.lab=0.8,cex.axis=0.8,cex.sub=0.8)
plot(x4,d4,type="l",main="30% Pareto / 70% Lognormal distribution",sub="Lognormal : mean=0 sd=0.5\nPareto : shape=1.5 scale=1 ",ylab="Pareto/Lognormal density",xlab="",col="dark magenta",lwd=2,cex.main=0.8,cex.lab=0.8,cex.axis=0.8,cex.sub=0.8)
plot(x4,d5,type="l",main="70% Pareto / 30% Lognormal distribution",sub="Lognormal : mean=0 sd=0.5\nPareto : shape=1.5 scale=1 ",ylab="Pareto/Lognormal density",xlab="",col="dark magenta",lwd=2,cex.main=0.8,cex.lab=0.8,cex.axis=0.8,cex.sub=0.8)

plot(x1,fdr1,type="l",main="Normal distribution",sub="mean=5 sd=1",col="dark magenta",xlab="",ylab="Normal cumulative df",lwd=2,cex.main=0.8,cex.lab=0.8,cex.axis=0.8,cex.sub=0.8)
abline(v=q1,col="red",lty=3)
abline(h=0.95,col="red",lty=3)
plot(x2,fdr2,type="l",main="Weibull distribution",sub="shape=1.5 scale=1",col="dark magenta",xlab="",ylab="Weibull cumulative df",lwd=2,cex.main=0.8,cex.lab=0.8,cex.axis=0.8,cex.sub=0.8)
abline(v=q2,col="red",lty=3)
abline(h=0.95,col="red",lty=3)
plot(x3,fdr3,type="l",main="Lognormal distribution",sub="mean=0 sd=0.5",col="dark magenta",xlab="",ylab="Lognormal cumulative df",lwd=2,cex.main=0.8,cex.lab=0.8,cex.axis=0.8,cex.sub=0.8)
abline(v=q3,col="red",lty=3)
abline(h=0.95,col="red",lty=3)
plot(x4,fdr4,type="l",main="30% Pareto / 70% Lognormal distribution",sub="Lognormal : mean=0 sd=0.5\nPareto : shape=1.5 scale=1 ",ylab="Pareto/Lognormal cumulative df",xlab="",col="dark magenta",lwd=2,cex.main=0.8,cex.lab=0.8,cex.axis=0.8,cex.sub=0.8)
abline(v=q4,col="red",lty=3)
abline(h=0.95,col="red",lty=3)
plot(x4,fdr5,type="l",main="70% Pareto / 30% Lognormal distribution",sub="Lognormal : mean=0 sd=0.5\nPareto : shape=1.5 scale=1 ",ylab="Pareto/Lognormal cumulative df",xlab="",col="dark magenta",lwd=2,cex.main=0.8,cex.lab=0.8,cex.axis=0.8,cex.sub=0.8)
abline(v=q5,col="red",lty=3)
abline(h=0.95,col="red",lty=3)

#Valeurs des quantiles d'ordre 0.95 pour chaque distribution

q1
#6.644854
q2
#2.078111
q3
#2.276017
q4
#2.917
q5
#4.828


